package com.cicadamob.contact.api.service.BlackName;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
/**
 * 黑名单 dbhelper
 * 类名称：BlackName_DbHelper
 * 类描述：
 * 创建者： mengxs
 * 创建时间：2015年5月22日
 */
public class BlackName_DbHelper extends SQLiteOpenHelper{
	private final static String DB_NAME = "blackname.db";
	/** 黑名单 **/
    public final static String TABLE_BLACK_NAME= "ts_black_name";
    /**拦截记录**/
    public final static String TABLE_INTERCEPT_HISTORY= "ts_intercept_history";
    
    public final static int VERSION=1;   
    
    private static BlackName_DbHelper instace=null;
    
	// 调用父类构造器，用于创建数据库
	private BlackName_DbHelper(Context context) {
		super(context, DB_NAME, null, VERSION);
	}
	
	public static BlackName_DbHelper newInstance(Context context) {
		if(instace==null){
			instace=new BlackName_DbHelper(context);
		}
		 return instace;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL("create table if not exists " + TABLE_BLACK_NAME
				+ "(_id integer primary key autoincrement,"
				+ "name varchar," 
				+ "tel varchar,"
				+ "type varchar,"
				+ "installed varchar,"
			    + "photo varchar)");
		
		db.execSQL("create table if not exists " + TABLE_INTERCEPT_HISTORY
				+ "(_id integer primary key autoincrement,"
				+ "name varchar," 
				+ "tel varchar,"
				+ "time varchar,"
				+ "type varchar,"
			    + "photo varchar)");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE IF EXISTS "+TABLE_BLACK_NAME);
		db.execSQL("DROP TABLE IF EXISTS "+TABLE_INTERCEPT_HISTORY);
	}
	
	public static final class TS_BLACK_NAME implements BaseColumns{
		private TS_BLACK_NAME(){
			
		}
		public static final String ID = "_id";
		public static final String NAME = "name";
		public static final String TEL = "tel";
		public static final String Photo = "photo";
		public static final String Type = "type";
		public static final String Installed = "installed";
		
	}
	
	public static final class  TS_INTERCEPT_HISTORY implements BaseColumns{
		private TS_INTERCEPT_HISTORY(){
			
		}
		public static final String ID = "_id";
		public static final String NAME = "name";
		public static final String TEL = "tel";
		public static final String Photo = "photo";
		public static final String Type = "type";
		public static final String Time = "time";
	}
}
